<template>
        <MyHeader></MyHeader>
    <div style="margin: 50px">
        <table class="demo-border">
            <tbody>
            <tr>
                <td class="text">角色</td>
                <td class="text">{{this.info.role}}</td>
                <td class="text" v-if="this.role === '超级管理员'">超级管理员</td>
            </tr>

            <tr>
                <td class="text">名称</td>
                <td class="text">{{this.info.name}}</td>
            </tr>

            <tr>
                <td class="text">账号</td>
                <td class="text">{{this.info.account}}</td>
            </tr>

            </tbody>
        </table>
    </div>
</template>

<script>
import {defineComponent, inject} from 'vue'
import MyHeader from "@/components/MyHeader.vue";
import axios from "axios";
import $cookies from "vue-cookie";

export default defineComponent({
    name: "UserInfo",
    components: {MyHeader},
    data(){
        return{
            myVueURL: inject('$vueURL'),
            myBaseURL: inject('$baseURL'),
            info:{
                role: "",
                name: "",
                account: ""
            }
        }
    },
    mounted() {
        const token = $cookies.get("token")

        if(token == null && token === "")
        {
            this.$message.error('提交失败！');//alert("请登录！")
            return
        }
        this.info.account = $cookies.get("account")
        axios({
            method:'post',
            url:'/user/getSelfInfo',
            baseURL:this.myBaseURL,
            params:{
                "token": token
            }
        }).then(response => {
            const user = response.data
            if(user != null)
            {
                this.info.name = user.name
                const roleId = user.roleId
                // 获取角色 name
                axios({
                    method:'post',
                    url:'/role/getInfo',
                    baseURL:this.myBaseURL,
                    params:{
                        "id": roleId
                    }
                }).then(res=>{
                    this.info.role = res.data.roleName
                })
            }
        })

    }
})
</script>

<style scoped>

</style>